//-------------------------------------------------------------------
//	Copyright (c) 2010-2011  Zhirnov Andrey
//	This file is part of the "UXGEN_ResourceConverter" project.
//	See copyright notice in "Converter.h".
//-------------------------------------------------------------------

#include "Test.h"

#define MODELS_PATH			OUTPUT_DIR

#define MESH_FILE			MODELS_PATH"tree1.dmd"
#define MULTIMESH_FILE		MODELS_PATH"SMUT\\SMUT.3ds"
#define FRAMEANIM_FILE		MODELS_PATH""
#define SCELETALMESH_FILE	MODELS_PATH"qshambler.md5mesh"
#define SCELETALANIM_FILE	MODELS_PATH"qshambler_attack01.md5anim"


bool MeshTest()
{
	uint	u_count = 0;

	HR_CHECK( SYSTEMS->pModelConv->Delete() );
	HR_CHECK( SYSTEMS->pModelConv->SetMaterialsPath( OUTPUT_DIR ) );
	HR_CHECK( SYSTEMS->pModelConv->Load( MESH_FILE, MC_MESH ) );
	HR_CHECK( SYSTEMS->pModelConv->GetComponentsCount( MC_MESH, u_count ) );
	HR_CHECK( SYSTEMS->pModelConv->SetOptimizeParams( 24, 0.01f, E_MESH_FLAGS(MF_OPTIMIZE_INDICES | MF_OPTIMIZE_VERTICES), MVP_PER_VERTEX ) );

	for (uint i = 0; i < u_count; ++i)
		HR_CHECK( SYSTEMS->pModelConv->ApplyToMesh( i ) );

	HR_CHECK( SYSTEMS->pModelConv->Save( OUTPUT_DIR"mesh.mdl", MC_MESH ) );
	return true;
}


bool MultiMeshTest()
{
	uint	u_count = 0;

	HR_CHECK( SYSTEMS->pModelConv->Delete() );
	HR_CHECK( SYSTEMS->pModelConv->SetFlags( E_MODEL_FLAGS(MDF_MERGE_MESHES | MDF_CONVERT_MATERIALS | MDF_CONVERT_TEXTURES) ) );
	HR_CHECK( SYSTEMS->pModelConv->SetMaterialsPath( OUTPUT_DIR ) );
	HR_CHECK( SYSTEMS->pModelConv->Load( MULTIMESH_FILE, MC_MESH ) );
	HR_CHECK( SYSTEMS->pModelConv->GetComponentsCount( MC_MESH, u_count ) );
	HR_CHECK( SYSTEMS->pModelConv->SetOptimizeParams( 24, 0.01f, E_MESH_FLAGS(MF_OPTIMIZE_INDICES | MF_OPTIMIZE_VERTICES), MVP_PER_VERTEX ) );
	
	//for (uint i = 0; i < u_count; ++i)
	//	HR_CHECK( SYSTEMS->pModelConv->ApplyToMesh( i ) );

	HR_CHECK( SYSTEMS->pModelConv->Save( OUTPUT_DIR"multimesh.mdl", E_MODEL_COMPONENT(MC_MESH | MC_MATERIAL) ) );
	return true;
}


bool SceletalMeshTest()
{
	HR_CHECK( SYSTEMS->pModelConv->Delete() );
	HR_CHECK( SYSTEMS->pModelConv->Load( SCELETALMESH_FILE, MC_MESH ) );
	HR_CHECK( SYSTEMS->pModelConv->Save( OUTPUT_DIR"sceletalmesh.mdl", MC_MESH ) );
	return true;
}


bool FrameAnimTest()
{
	/*SYSTEMS->pModelConv->Delete();
	SYSTEMS->pModelConv->Load( MESH_FILE, MC_MESH );
	SYSTEMS->pModelConv->Save( OUTPUT_DIR"mesh.mdl", MC_MESH );*/
	return true;
}


bool SceletalAnimTest()
{
	HR_CHECK( SYSTEMS->pModelConv->Delete() );
	HR_CHECK( SYSTEMS->pModelConv->Load( SCELETALMESH_FILE, MC_MESH ) );
	HR_CHECK( SYSTEMS->pModelConv->Load( SCELETALANIM_FILE, MC_ANIMATION ) );
	HR_CHECK( SYSTEMS->pModelConv->Save( OUTPUT_DIR"sceletal.mdl", E_MODEL_COMPONENT( MC_MESH | MC_ANIMATION ) ) );
	return true;
}


bool TestModelConverting(IConverter *pConv)
{
	bool	ret = true;

	//ret &= MeshTest();
	ret &= MultiMeshTest();
	//ret &= SceletalMeshTest();
	//ret &= FrameAnimTest();
	//ret &= SceletalAnimTest();

	return ret;
}